import COS from 'cos-js-sdk-v5'
import api from '../api/index'

const cos = new COS({
  getAuthorization: function (options, callback) {
    // 异步获取临时密钥
    api.getCosSignature().then(function (rep) {
      var data = rep.data
      console.log('sign:', data)
      callback({
        TmpSecretId: data.sign.tmpSecretId,
        TmpSecretKey: data.sign.tmpSecretKey,
        XCosSecurityToken: data.sign.sessionToken,
        ExpiredTime: data.expiredTime
      })
    })
  }
})

export default cos
